/**
 * @author huangyong
 */
public class ShellsSort {
    public static void sort(int[] array) {
        int gap = array.length;
        do {
            gap /= 2;
            for (int i = 0; i < gap; i++) {
                for (int j = i + gap; j < array.length; j += gap) {
                    int k = j - gap;
                    while (k >= 0 && array[k] > array[k + gap]) {
                        int temp = array[k];
                        array[k] = array[k + gap];
                        array[k + gap] = temp;
                        k -= gap;
                    }
                }
            }
        } while (gap != 1);
    }
}
